using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EngineGame;
using System.Threading;
using Microsoft.Xna.Framework;
namespace WarsOnRiceFields
{
    class Loading : GameScreen
    {
        private Thread backgroundThread;
        private Sprite LogoImage;
        public Loading()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.0);
            TransitionOffTime = TimeSpan.FromSeconds(0.0);
        }
        void BackgroundLoadContent()
        {
            LogoImage = new Sprite(ScreenManager.Game.Content, "Images/logo");
        }
        public override void LoadContent()
        {
            if (backgroundThread == null)
            {
                backgroundThread = new Thread(BackgroundLoadContent);
                backgroundThread.Start();
            }
          
            base.LoadContent();
        }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            
            if (backgroundThread != null && backgroundThread.Join(10))
            {
                backgroundThread = null;
                this.ExitScreen();
                ScreenManager.AddScreen(new Logo());
                ScreenManager.Game.ResetElapsedTime();
            }
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
         public override void Draw(GameTime gameTime)
        {
            ScreenManager.SpriteBatch.Begin();
            LogoImage.Draw(ScreenManager.SpriteBatch);
            ScreenManager.SpriteBatch.End();
            base.Draw(gameTime);
        }
         
    }
}
